/******************************************************************************
 * * hal_ble_profile.h - implementation of ble profile interface
 *
 * *(C) Copyright 2021 Asr International Ltd.
 * * All Rights Reserved
 * ******************************************************************************/

#ifndef HAL_BLE_PROFILE_H_
#define HAL_BLE_PROFILE_H_

#ifdef __cplusplus
extern "C" {
#endif

#include "hal_bt.h"

#if USE_LV_BLE_DEMO != 0

#include "bt_inc/bt_api_le.h"

enum {
    BLE_PROFILE_HEART_RATE = 0,
    BLE_PROFILE_FIND_ME,
    BLE_PROFILE_MAX,
};
typedef uint8_t BLE_PROFILE_T;

enum {
    BLE_STATE_NULL = 0,
    BLE_STATE_IDLE,
    BLE_STATE_SCAN,
    BLE_STATE_CONNECTING,
    BLE_STATE_CONNECTED,
    BLE_STATE_DISCONNECTING,
};
typedef uint8_t BLE_STATE_T;

typedef struct {
    uint16_t handle;
    uint16_t value_handle;
    uint8_t propertis;
    struct le_uuid_common uuid;
    uint16_t ccc;
} ble_characteristic_record_t;

typedef struct {
    uint16_t start_handle;
    uint16_t end_handle;
    struct le_uuid_common uuid;
    lv_ll_t characteristic; // ble_characteristic_record_t
} ble_service_record_t;

typedef uint32_t (*ble_get_serv_cb)(struct gatt_attr * attrs);
typedef int32_t (*ble_att_event_handle_cb)(struct bt_task_event * msg);
typedef void (*ble_deinit_cb)(void);

void ble_add_serv(void);
void ble_del_serv(void);
void ble_profile_cb_reg(BLE_PROFILE_T profile, ble_get_serv_cb get_cb,
                        ble_att_event_handle_cb event_cb, ble_deinit_cb deinit_cb);
BLE_STATE_T ble_get_state(void);
void ble_conn_est(BLE_PROFILE_T profile);
void ble_conn_disc(BLE_PROFILE_T profile);
lv_ll_t * ble_get_service_record(void);
bool ble_is_profile_process(BLE_PROFILE_T profile);

// for heart rate profile
void ble_hrp_init(void);

// for find me profile
void ble_fmp_init(void);

#endif /*USE_LV_BLE_DEMO*/

#ifdef __cplusplus
}
#endif

#endif/*HAL_BLE_PROFILE_H_*/
